<?php
/* 
* @Author: LDF QQ 47121862
* @Date:   2014-06-07 19:20:11
* @Last Modified by:   LDF QQ 47121862
* @Last Modified time: 2014-06-12 17:41:32
*/
class XilieControl extends ConfigControl{
	//系列首页列表
	function index(){
		//分配slide
		$this->slide=M('xilie')->where('slide=1')->limit(6)->all();
		//分配xilie
		$page=new Page(M('xilie')->order('xid DESC')->count());
		$this->xilie = M('xilie')->order('xid DESC')->limit($page->limit())->all();
		$this->page=$page->show();
		$this->display();
	}
	//详细剧情
	function content(){
		$xid=Q('xid',0,'intval');
		//关联用户表
		$model = V('xcomment');
		$model->view=array(
			'user'=>array(
				'type'=>INNER_JOIN,
				'on'=>'xcomment.uid=user.uid'
			)
		);
		if(IS_POST){ //ajax显示评论
			sleep(1); //模拟网络延迟加载等待效果
			// 查找系列评论 并分配
			$total=M('xcomment')->where(array('xid'=>$xid))->count();
			$page=new Page($total,2);
			
			$this->comment=$model->where(array('xid'=>$xid))->order('cxid DESC')->limit($page->limit())->all();
			$path = ROOT_PATH.'data/Ajax/xilieCommentAjax.html';
			$this->page=$page->show();
			$data = $this->fetch($path);
			echo $data;die;
		}else{
			$xilie = M('xilie')->find($xid);
			$xilie['juji']=M('juji')->where('xid='.$xid)->order('jid DESC')->all();
			if(isset($_GET['jid'])){
				$juji = M('juji')->find(Q('jid',0,'intval'));
				$xilie['firstUrl']=$juji['url'];
				$xilie['jname']=$juji['intro'];
			}
			$xilie['num'] = isset($_GET['num']) ? Q('num',0,'intval') : '';
			// 查找系列评论 并分配
			$total=M('xcomment')->where(array('xid'=>$xid))->count();
			$page=new Page($total,2);
			$this->comment=$model->where(array('xid'=>$xid))->order('cxid DESC')->limit($page->limit())->all();
			$this->page=$page->show();
			
			$this->field=$xilie;
			$this->display();
		}
	}
	//ajax系列顶和不顶
	function ding(){
		$xid=Q('xid',0,'intval');
		$stat=Q('stat',0,'intval');
		if(!isset($_COOKIE[$xid])){
			$stat?M('xilie')->inc('ding','xid='.$xid,1):M('xilie')->inc('down','xid='.$xid,1);
			setcookie($xid,1,time()+3600*24,'/'); //1天过期
		}else{
			$stat = 9;
		}
		echo $stat;die;
	}

}
